{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}	
	<div class="layui-body"> 
{include file='Public/crumbs' /}
		<!-- 内容主体区域 -->
		<div class="shu-body">
			<div class="layui-fluid">
				<form class="layui-form layui-form-pane" action="" method="post">
				<input type="hidden" name="id" id="id"  value="{notempty name='single'}{$single['id']}{/notempty}">
                <input type="hidden" name="pid" id="pid"  value="{$pid}">
				
				<div class="layui-form-item">
				  	<label class="layui-form-label">文章标题</label>
				  	<div class="layui-input-block">
						<input type="text" name="title" id="title" placeholder="文章标题" class="layui-input" value="{notempty name='single'}{$single['title']}{/notempty}" required  lay-verify="required" autocomplete="off">
				  	</div>
				</div>
				
				
				<div class="layui-form-item">
				  	<label class="layui-form-label">SEO标题</label>
				  	<div class="layui-input-inline">
					<input type="text" name="seotitle" id="seotitle" placeholder="SEO标题" class="layui-input" value="{notempty name='single'}{$single['seotitle']}{/notempty}">
				  	</div>
					<div class="layui-form-mid layui-word-aux">如果设置SEO标题，将会在IE标题栏显示SEO标题</div>
				</div>
				<div class="layui-form-item">
				  	<label class="layui-form-label">关键词</label>
				  	<div class="layui-input-inline">
					<input type="text" name="seokeywords" id="seokeywords" placeholder="关键词" class="layui-input" value="{notempty name='single'}{$single['seokeywords']}{/notempty}">
				  	</div>
					<div class="layui-form-mid layui-word-aux">文章关键词</div>
				</div>
				<div class="layui-form-item layui-form-text">
				  	<label class="layui-form-label">文章摘要</label>
				  	<div class="layui-input-block">
					<textarea name="seodescription" id="seodescription" placeholder="文章摘要" class="layui-textarea">{notempty name='single'}{$single['seodescription']}{/notempty}</textarea>
				  	</div>
					<div class="layui-form-mid layui-word-aux">文章摘要、描述。</div>
				</div>
				<div class="layui-form-item">
				  	<label class="layui-form-label">排序</label>
				  	<div class="layui-input-inline">
					<input type="text" name="o" id="o" placeholder="排序" class="layui-input" value="{notempty name='single'}{$single['o']}{/notempty}">
				  	</div>
					<div class="layui-form-mid layui-word-aux">数字越大越靠前</div>
				</div>
				
				<!--layui单图上传-->
			    <div class="layui-form-item">
					<label class="layui-form-label">缩略图</label>
					<div class="layui-input-inline">
				 		<a class="layui-btn" id="image" style="float: left;"><i class="layui-icon">&#xe67c;</i>上传图片</a>
				  		<input type="text" name="logo" class="layui-input" style="position: absolute; left: 111px; top: 0px;" placeholder="仅支持jpg、gif、png、bmp、jpeg，且小于1MB。" value="{notempty name='single'}{$single['logo']}{/notempty}">
					</div>
			    </div>
				<div class="layui-form-item picdemo">
				  	<label class="layui-form-label" style="height:100px; line-height:80px;">预览图</label>
				  	<div class="layui-input-inline">
						<div id="layer-photos-demo" class="layer-photos-demo">
							<img src="__ROOT__{$single['logo']}" layer-src="__ROOT__{$single['logo']}" width="111" height="100"> 
						</div>
				  	</div>
				</div>
				<div class="layui-form-item picdemo1">
				  	<label class="layui-form-label" style="height:100px; line-height:80px;">预览图</label>
				  	<div class="layui-input-inline">
						<div id="layer-photos-demo1" class="layer-photos-demo">
							<img id="pic" src="__ROOT__{$single['logo']}" layer-src="__ROOT__{$single['logo']}" width="111" height="100"> 
						</div>
				  	</div>
				</div>
				
				
				<!--单图上传-->
				<div class="layui-form-item" style="display:none;">
				  	<label class="layui-form-label" style="height:100px; line-height:80px;">缩略图</label>
				  	<div class="layui-input-inline">
						{notempty name='single'}
						{:UpImage("logo1",100,100,$single['logo1'])}
						{else /}
						{:UpImage("logo1",100,100,null)}
						{/notempty}
				  	</div>
					<div class="layui-form-mid layui-word-aux" style="line-height:80px">仅支持jpg、gif、png、bmp、jpeg，且小于1MB。</div>
				</div>
				
				
				
				
				<div class="layui-form-item layui-form-text">
				  	<label class="layui-form-label">文章内容</label>
				  	<div class="layui-input-block">
					<textarea style="height:300px;" name="content" id="content" placeholder="文章内容" class="layui-textarea">{notempty name='single'}{$single['content']}{/notempty}</textarea>
				  	</div>
				</div>
				
				
				<div class="layui-form-item">
				  <div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				  </div>
				</div>
			  </form>
			</div>
		</div>
		<!-- 内容主体区域 END-->
	</div>
{include file='Public/footer' /}	
<script>
//图片预览的显示与隐藏
if($('input[name=logo]').val() == ""){
	$(".picdemo").hide();
	$(".picdemo1").hide();	
}else{
	$(".picdemo").show();
	$(".picdemo1").hide();	
}
	
layui.use(['jquery','form','layer','laydate','upload'], function(){
	var form = layui.form,jq = layui.$,layer=layui.layer,laydate = layui.laydate,upload = layui.upload;	
	//日期
	laydate.render({
    	elem: '#t' //指定元素
  	});
	
	//预览图
	layer.photos({
	  photos: '#layer-photos-demo'
	  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
	});	
	
	//上传
  	upload.render({
    	url: "{:url('Upload/picup')}"
    	,elem:'#image'
		,field:'FileName'
    	,before: function(input){
      		loading = layer.load(2, {
        		shade: [0.2,'#000']
      		});
    	}
    	,done: function(res){
			if(res.code == 1){
				//console.log(res);
      			layer.close(loading);
      			jq('input[name=logo]').val(res.data); //给隐藏的文本框赋值

				pic.src = ""+res.data; //给图片赋值
				jq("#pic").attr('layer-src',res.data);  //给图片的layer-src属性赋值
				//预览新上传的图
				layer.photos({
				  photos: '#layer-photos-demo1'
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
				jq(".picdemo").hide();   //隐藏div
				jq(".picdemo1").show();   //显示div
      			layer.msg(res.msg, {icon: 1, time: 1000});
			}else{
				layer.close(loading);
				layer.msg(res.msg, {icon: 2, anim: 6, time: 1000});
			}
    	}
  	});
 
	//提交
	form.on('submit(formDemo)', function(data){
		loading = layer.load(2, {
			shade: [0.2,'#000']
		});
		var param = data.field;
		jq.post("{:url('update')}",param,function(data){
			//console.log(data);
			if(data.code == 1){
				layer.close(loading);
				layer.msg(data.msg, {icon: 1, time: 1000}, function(){
					//location.reload();
					location.href=data.url;
				});
			}else{
				layer.close(loading);
				layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
			}
		});
	return false;
	});
	
	////编辑器
	var editor = new wangEditor('content');
	editor.config.uploadImgUrl = "{:url('Upload/picupdate')}";
	editor.config.uploadImgFileName = 'FileName';
	editor.config.menus = $.map(wangEditor.config.menus, function(item, key) {
//	if (item === 'img') {  //屏蔽图片
//	return null;
//	}
	if (item === 'eraser') {
	return null;
	}
	if (item === 'video') {
	return null;
	}
	if (item === 'location') {
	return null;
	}
	return item;
	});
	editor.config.pasteText = true;
	editor.create();
	
});
</script>